﻿#include "companynetworkaccessmanager.h"

const static QString COMPANY_BASE_URL = BASE_URL+"company/";
const static QString COMPANY_ADD_COMPANY_URL = COMPANY_BASE_URL+"addCompany";
const static QString COMPANY_UPDATE_COMPANY_URL = COMPANY_BASE_URL+"updateCompany";
const static QString COMPANY_QUERY_COMPANY_URL = COMPANY_BASE_URL+"queryCompany";
const static QString COMPANY_JOIN_COMPANY_URL = COMPANY_BASE_URL+"joinCompany";
const static QString COMPANY_UPDATE_CATEGORY_URL = COMPANY_BASE_URL+"updateCategory";
const static QString COMPANY_UPDATE_ITEM_CATEGORY = COMPANY_BASE_URL+"updateItemCategory";
const static QString COMAPNY_DELETE_ITEM_CATEGORY = COMPANY_BASE_URL+"deleteItemCategory";
const static QString COMPANY_UPDATE_COMPANYDATA = COMPANY_BASE_URL+"updateCompanyData";
const static QString COMPANY_HOME_COUNT = COMPANY_BASE_URL+"homeCount";
CompanyNetworkAccessManager::CompanyNetworkAccessManager(QObject *parent) : BaseNetworkAccessManager(parent)
{

}

void CompanyNetworkAccessManager::addCompany(QString username, QString companyName, QString contact)
{
    QByteArray data;
    data.append("username="+username+"&");
    data.append("companyName="+companyName+"&");
    data.append("contact="+contact);

    doPost(COMPANY_ADD_COMPANY_URL, data);
}

void CompanyNetworkAccessManager::updateCompany(
        QString username,
        QString companyId,
        QString taxRate,
        QString companyName,
        QString contact,
        QString tel,
        QString fax,
        QString website,
        QString email,
        QString province,
        QString city,
        QString district,
        QString address,
        QString account,
        QString introduction,
        QString ticketCompanyName,
        QString taxNum,
        QString bank,
        QString ticketAccount,
        QString ticketTel,
        QString ticketAddress)
{
    QByteArray data;
    data.append("username="+username+"&");
    data.append("companyId="+companyId+"&");
    data.append("taxRate="+taxRate+"&");
    data.append("companyName="+companyName+"&");
    data.append("contact="+contact+"&");
    data.append("tel="+tel+"&");
    data.append("fax="+fax+"&");
    data.append("website="+website+"&");
    data.append("email="+email+"&");
    data.append("province="+province+"&");
    data.append("city="+city+"&");
    data.append("district="+district+"&");
    data.append("address="+address+"&");
    data.append("account="+account+"&");
    data.append("introduction="+introduction+"&");
    data.append("ticketCompanyName="+ticketCompanyName+"&");
    data.append("taxNum="+taxNum+"&");
    data.append("bank="+bank+"&");
    data.append("ticketAccount="+ticketAccount+"&");
    data.append("ticketTel="+ticketTel+"&");
    data.append("ticketAddress="+ticketAddress);

    doPost(COMPANY_UPDATE_COMPANY_URL, data);
}

void CompanyNetworkAccessManager::queryCompany(QString username, QString companyId)
{
    QByteArray data;
    data.append("username="+username+"&");
    data.append("companyId="+companyId);

    doPost(COMPANY_QUERY_COMPANY_URL, data);
}

void CompanyNetworkAccessManager::joinCompany(QString username, QString companyId)
{
    QByteArray data;
    data.append("username="+username+"&");
    data.append("companyId="+companyId);

    doPost(COMPANY_JOIN_COMPANY_URL, data);
}

void CompanyNetworkAccessManager::updateCategory(Company::CategoryType categoryType, QString companyId, QString category)
{
    QByteArray data;
    data.append(QString("categoryType=%1&").arg(categoryType));
    data.append("companyId="+companyId+"&");
    data.append("category="+category);

    doPost(COMPANY_UPDATE_CATEGORY_URL, data);
}

void CompanyNetworkAccessManager::updateCategory(
        Company::CategoryType categoryType,
        QString username,
        QString companyId,
        QString oldPrimaryDirectory,
        QString oldSecondaryDirectory,
        QString newPrimaryDirectory,
        QString newSecondaryDirectory)
{
   QByteArray data;
   data.append("categoryType="+QString("%1").arg(categoryType)+"&");
   data.append("username="+username+"&");
   data.append("companyId="+companyId+"&");
   data.append("oldPrimaryDirectory="+oldPrimaryDirectory+"&");
   data.append("oldSecondaryDirectory="+oldSecondaryDirectory+"&");
   data.append("newPrimaryDirectory="+newPrimaryDirectory+"&");
   data.append("newSecondaryDirectory="+newSecondaryDirectory);

   doPost(COMPANY_UPDATE_ITEM_CATEGORY, data);
}

void CompanyNetworkAccessManager::deleteCategory(
        Company::CategoryType categoryType,
        QString username,
        QString companyId,
        QString primaryDirectory,
        QString secondaryDirectory)
{
    QByteArray data;
    data.append(QString("categoryType=%1&").arg(categoryType));
    data.append("username="+username+"&");
    data.append("companyId="+companyId+"&");
    data.append("primaryDirectory="+primaryDirectory+"&");
    data.append("secondaryDirectory="+secondaryDirectory);

    doPost(COMAPNY_DELETE_ITEM_CATEGORY, data);
}

void CompanyNetworkAccessManager::updateCompanyData(QString username, QString companyId){
    QByteArray data;

    data.append("username="+username+"&");
    data.append("companyId="+companyId+"&");

    doPost(COMPANY_UPDATE_COMPANYDATA, data);
}

void CompanyNetworkAccessManager::homeCount(
        int type,
        QString username,
        QString companyId,
        double oldValue,
        double countValue){
    QByteArray data;
    data.append("type="+QString("%1").arg(type)+"&");
    data.append("username="+username+"&");
    data.append("companyId="+companyId+"&");
    data.append("oldValue="+QString("%1").arg(oldValue)+"&");
    data.append("countValue="+QString("%1").arg(countValue));

    doPost(COMPANY_HOME_COUNT, data);
}
